# 遍历列表
a = [1,3,9,5,7,8]
for i in a:
    print(i)

# 遍历列表及索引 enumerate()
a = ["Python","人工智能","大数据"]
for index, name in enumerate(a):
    print(index, name)

# 遍历元组 enumerate()
a = ("Python","人工智能","大数据")
for index, name in enumerate(a):
    print(index, name)

# 遍历字典 items() keys() values()
x={
    "李立宗":18,
    "刘能":88,
    "赵四":99,
    "tony":100
}
print("items(): 返回字典内key-value对")
for a,b in x.items():
    print(a,b)
print("keys(): 返回字典内所有key列表")
for c in x.keys():
    print(c)
print("values(): 返回字典中所有value列表")
for d in x.values():
    print(d)

# 遍历字符串
s="PYTHON"
for i in s:
    print(i)

# 6.1 练习
a = [234,211,2,-292,-92,12]
for i in a:
    if i>0:
        print(i, end=" ")
print()

# 6.2 练习
s=0
for i in range(1, 101):
    s = s + i
print(s)

x=range(8,20,3)  # 生成可迭代对象（类型是对象）
print(x)
print(list(x))   # 把可迭代对象转为一个列表

print(sum(range(1,101)))

for i in range(1, 100):
    if i % 7 == 0:
        print(i)
print("------------------------------------------------")

# 6.3
x=7
while x<100:
    print(x, end=" ")
    x+=7
print()
x=1
while x<100:
    if x%7==0:
        print(x, end=" ")
    x+=1
print()

# 6.4
x=[34,2,3,55,44,11,9,0,12,14,13]
even=0
odd=0
i=0
while i<len(x):
    if x[i]%2==0:
        even+=1
    else:
        odd+=1
    i+=1
print("even", even)
print("odd", odd)

# 6.5
x=[34,2,30,54,44,11,9,0,12,14,13]
i=0
while i<len(x):
    if not x[i]%2 == 0:
        print("列表有奇数")
        break
    i+=1
    # print("列表无奇数")

# 6.6
a=[34,56,78,98,99,100,123,78,45,65,39,97,99]
for i in a:
    if i%3==0:
        print("被3整除的数", i)
        continue
    



